<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改产品分类')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-category-edit" th:object="${productCategory}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">上级分类ID：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />
                        <input class="form-control" type="text" onclick="selectCategoryTree()" id="treeName" readonly="true" th:field="*{parentName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">分类名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">banner图：</label>
                <input name="bannerImg" th:value="*{bannerImg}" type="hidden">
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input name="file" id="fileinput-demo-1" type="file" multiple>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">分类级别</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('category_level')}">
                        <input type="radio" th:id="${dict.dictCode}" name="level" th:value="${dict.dictValue}" th:field="*{level}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">显示状态</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('brand_show_status')}">
                        <input type="radio" th:id="${dict.dictCode}" name="showStatus" th:value="${dict.dictValue}" th:field="*{showStatus}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" th:field="*{sort}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">banner图：</label>
                <input name="icon" th:value="*{icon}" type="hidden">
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input name="file" id="fileinput-demo-2" type="file" multiple>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">关键字：</label>
                <div class="col-sm-8">
                    <input name="keywords" th:field="*{keywords}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-8">
                    <input name="description" th:field="*{description}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
        var prefix = ctx + "mall/category";
        $("#form-category-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-category-edit').serialize());
            }
        }

        /*产品分类-新增-选择父部门树*/
        function selectCategoryTree() {
            var options = {
                title: '产品分类选择',
                width: "380",
                url: prefix + "/selectCategoryTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
               $("#treeId").val(body.find('#treeId').val());
               $("#treeName").val(body.find('#treeName').val());
               layer.close(index);
        }

        /**
         * 图片上传
         */
        $("#fileinput-demo-1").fileinput({
            'theme': 'explorer-fas',
            'uploadUrl': ctx +'aliyun/upload',
            autoReplace:true,
            initialPreviewAsData: true,
            overwriteInitial:true,
            initialPreview:[$("input[name='bannerImg']").val()],
            uploadExtraData:{ //额外参数，将不同的文件存放不同的目录下
                "baseDir":"advertise"
            }
        }).on("fileuploaded", function(event, data, previewId, index) {//上传成功回调
            $("input[name='bannerImg']").val(data.response.url);
            console.log(data.response.url);
        });

        /**
         * 图片上传
         */
        $("#fileinput-demo-2").fileinput({
            'theme': 'explorer-fas',
            'uploadUrl': ctx +'aliyun/upload',
            autoReplace:true,
            initialPreviewAsData: true,
            overwriteInitial:true,
            initialPreview:[$("input[name='icon']").val()],
            uploadExtraData:{ //额外参数，将不同的文件存放不同的目录下
                "baseDir":"advertise"
            }
        }).on("fileuploaded", function(event, data, previewId, index) {//上传成功回调
            $("input[name='icon']").val(data.response.url);
            console.log(data.response.url);
        });
    </script>
</body>
</html>